var neirong = new Vue({
	el: '#noveldetail',
	data: {
		chapter: 'N/A',
		catalogue: 'N/A',
		title: 'N/A',
		next: 'N/A',
		content: 'N/A',
		fonts: [{id:'默认', value: ''}, 
			{id:'a', value: ''},
			{id:'b', value: ''},
			{id:'c', value: ''},
			{id:'d', value: ''}],
		sizes: [{id:'12', value: { fontSize: '1.2rem'}},
			{id:'13', value: { fontSize: '1.3rem'}},
			{id:'14', value: { fontSize: '1.4rem'}},
			{id:'15', value: { fontSize: '1.5rem'}},
			{id:'16', value: { fontSize: '1.6rem'}},
			{id:'17', value: { fontSize: '1.7rem'}},
			{id:'18', value: { fontSize: '1.8rem'}},
			{id:'19', value: { fontSize: '1.9rem'}},
			{id:'20', value: { fontSize: '2rem'}},
			{id:'21', value: { fontSize: '2.1rem'}},
			{id:'22', value: { fontSize: '2.2rem'}},
			{id:'23', value: { fontSize: '2.3rem'}}],
		colors: [{id:{ backgroundColor:'black'}, value: { color:'black'}},
			{id:{ backgroundColor:'#555'}, value: { color:'#555'}},
			{id:{ backgroundColor:'#aaa'}, value: { color:'#aaa'}},
			{id:{ backgroundColor:'white'}, value: { color:'white'}},
			{id:{ backgroundColor:'#EEE0E5'}, value: { color:'#EEE0E5'}},
			{id:{ backgroundColor:'#CDB5CD'}, value: { color:'#CDB5CD'}}],
		bgcolors: [{id:{ backgroundColor:'#000'}, value: { backgroundColor:'#000'}},
			{id:{ backgroundColor:'#555'}, value: { backgroundColor:'#555'}},
			{id:{ backgroundColor:'#aaa'}, value: { backgroundColor:'#aaa'}},
			{id:{ backgroundColor:'#fff'}, value: { backgroundColor:'#fff'}},
			{id:{ backgroundColor:'#C7EDCC'}, value: { backgroundColor:'#C7EDCC'}}, // 护眼绿
			{id:{ backgroundColor:'#CDBE70'}, value: { backgroundColor:'#CDBE70'}}, // 牛皮纸（深）
			{id:{ backgroundColor:'#FFEC8B'}, value: { backgroundColor:'#FFEC8B'}},  // 牛皮纸（浅）
			{id:{ backgroundColor:'#FFFACD'}, value: { backgroundColor:'#FFFACD'}},  // 牛皮纸（淡）
			{id:{ backgroundColor:'#CDB5CD'}, value: { backgroundColor:'#CDB5CD'}},  // 浅紫色
			{id:{ backgroundColor:'#FFF0F5'}, value: { backgroundColor:'#FFF0F5'}},  // 浅粉色
			{id:{ backgroundColor:'#EEE0E5'}, value: { backgroundColor:'#EEE0E5'}},  // 暗粉色
			{id:{ backgroundColor:'#191e66'}, value: { backgroundColor:'#191e66'}},  // 深蓝
			{id:{ backgroundColor:'#696969'}, value: { backgroundColor:'#696969'}}], // 腚灰
		font_idx: 0,
		size_idx: 1,
		color_idx: 0,
		bgcolor_idx: 3,
		isOff: true,
		light: '夜间',
		localData: {  //使用pass表示该数据为空，所有书对象里都是数组类型，存放最近的三个对象
			latelyType: [{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			}, {
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			},{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			},{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			}], //最近浏览的小说类别
			latelyList: [{ // 最近看过的小说
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			},{
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			},{
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			}],
			latelySearch: ['', '', '', '', ''] //最近查询（允许存放5个结果）
		}
	},
	methods: {
		getdata: function () {
			var that = this;
			$.ajax({
				type : 'POST',
				url : '/novel/novel_data/',
				dataType : "json",//数据类型为json
				data: {
					what: 'detail',
					chapter: $('span.hidden')[0].innerHTML,
					site: $('span.hidden')[1].innerHTML
				},
				success : function(data){
					if(data.result){
						data = data.data;
						that.content = data.content;
						that.chapter = data.chapter;
						that.catalogue = data.catalogue;
						that.title = data.title;
						that.next = data.next;
					}
					$('img#load').addClass('hidden');
				},
				error:function(msg){
					console.log("ajax error msg",msg);
					$('img#load').addClass('hidden');
					$('#promptbtn').click();
				}
			});
		},
		selectColor: function (idx) {
			this.color_idx = idx;
		    try{ localStorage.setItem("color_idx", idx); } catch (err) {
		    	console.log(err);
		    }
		},
		selectBgColor: function (idx) {
		    try{ localStorage.setItem("bgcolor_idx", idx); } catch (err) {
		    	console.log(err);
		    }
			this.bgcolor_idx = idx;
		},
		selectSize: function (idx) {
		    try{ localStorage.setItem("size_idx", idx); } catch (err) {
		    	console.log(err);
		    }
			this.size_idx = idx;
		},
		selectFont: function (idx) {
			this.font_idx = idx;
		},
		douseTheGlim: function(){
			if(this.isOff){
				this.color_idx = 2;
				this.bgcolor_idx = 0;
				this.light = '白天';
			}else{
				this.color_idx = 0;
				this.bgcolor_idx = 3;
				this.light = '夜间';
			}
			this.isOff = !this.isOff;
		    localStorage.setItem("color_idx", this.color_idx);
		    localStorage.setItem("bgcolor_idx", this.bgcolor_idx);
		    localStorage.setItem("isOff", this.isOff);
		    localStorage.setItem("light", this.light);
		}
	},
	computed: {
		catalogue_page: function () {
			if($('span.hidden')[1].innerHTML == 'bqg')
				return '/novel/list/catalogue/?site=bqg&catalogue=http://www.biquge.com.tw'
					+ this.catalogue;
			else if($('span.hidden')[1].innerHTML == 'ddxs')
				return '/novel/list/catalogue/?site=ddxs&catalogue=http://www.23us.so'
					+ this.catalogue;
        },
		next_page: function () {
			if($('span.hidden')[1].innerHTML == 'bqg')
				return './?chapter=' + this.next + '&site=' + $('span.hidden')[1].innerHTML
			if($('span.hidden')[1].innerHTML == 'ddxs')
				return './?chapter=http://www.23us.so' + this.next + '&site=' + $('span.hidden')[1].innerHTML
        },
		cntColor: function () {
			return this.colors[this.color_idx].value
		},
		cntBgColor: function () {
			return this.bgcolors[this.bgcolor_idx].value
		},
		cntSize: function () {
			return this.sizes[this.size_idx].value
		},
		cntFont: function () {
			return {
				fontFamily: this.fonts[this.font_idx].value
			}
		}
	},
	mounted: function () {
		$('img#load').removeClass('hidden');
		try {
			var data = localStorage.getItem('lately');
			if(data){
				this.localData = JSON.parse(data);
			}else{
				localStorage.setItem('lately', JSON.stringify(this.localData));
			}
		} catch (err) {
			console.log(err);
		}
		this.getdata();
		try {
		    this.color_idx = localStorage.getItem("color_idx") || 0;
		    this.bgcolor_idx = localStorage.getItem("bgcolor_idx") || 3;
		    this.size_idx = localStorage.getItem("size_idx") || 1;
		    this.isOff = localStorage.getItem("isOff") || true;
		    this.light = localStorage.getItem("light") || '夜间';
        } catch (err) {
            console.log(err);
        }
	}
});
